package com.qf.api;

        import org.springframework.cloud.openfeign.FeignClient;
        import org.springframework.web.bind.annotation.*;

        import java.util.Map;
        import java.util.Set;

/**
 * @author WuZiYu
 * @date 2022-6-3 上午 12:14
 */
//@FeignClient(name = "sms-platform-cache",fallback = )//降级处理
@FeignClient(name = "sms-platform-cache")
@RequestMapping("/cache")
public interface CacheFeign {

    /**
     * 查询Redis中的Hash   通过Key查询Map
     * @param key
     * @return
     */
    @RequestMapping(value = "/hmget/{key}", method = RequestMethod.GET)
    public Map hMGet(@PathVariable("key") String key);

    /**
     * 查询hash类型  只查一个
     * @param key
     * @param field
     * @return
     */
    @RequestMapping(value = "/hget/{key}/{field}",method = RequestMethod.POST)
    public String hget(@PathVariable(value = "key") String key,@PathVariable(value = "field") String field);


    //通配获取key集合
    @GetMapping(value = "/keys/{key}")
    public Set<String> keys(@PathVariable(value = "key")String key);
    /**
     * 保存key-value到redis的String结构中,传入的value是Object类型
     * @param key
     * @param value
     * @return
     */
    @PostMapping("/save2cache-object")
    public boolean save(@RequestParam String key,@RequestParam Object value);

    @RequestMapping(value = "/get/{key}", method = RequestMethod.GET)
    public String get(@PathVariable("key") String key);

    @RequestMapping(value = "/get-object/{key}", method = RequestMethod.GET)
    public Object getObject(@PathVariable("key") String key);

    @RequestMapping(value = "/delete", method = RequestMethod.POST)
    public boolean del(@RequestParam("keys") String... keys);

    @RequestMapping(value = "/hmset/{key}", method = RequestMethod.POST)
    public boolean hMSet(@PathVariable("key") String key, @RequestBody Map map);


    @RequestMapping(value = "/save2cache", method = RequestMethod.POST)
    public boolean set(@RequestParam("key") String key, @RequestParam("value") String value, @RequestParam("expireSecond") Long expireSecond);

    @RequestMapping(value = "/incr", method = RequestMethod.GET)
    public Long incr(@RequestParam("key") String key, @RequestParam("delta") long delta);


    // set结构的add操作
    @RequestMapping(value = "/sadd/{key}",method = RequestMethod.POST)
    public boolean sadd(@PathVariable(value = "key")String key,@RequestParam String... set);

    // set结构的add操作
    @RequestMapping(value = "/sadd-object/{key}",method = RequestMethod.POST)
    public boolean saddObject(@PathVariable(value = "key")String key,@RequestBody Set<Map> set);


    // set结构中的members,获取set中的全部数据
    @RequestMapping(value = "/smembers/{key}",method = RequestMethod.GET)
    public Set<String> smembers(@PathVariable(value = "key") String key);


    // zset结构的根据分数查询数据
    @RequestMapping(value = "/zrangebyscore/{key}",method = RequestMethod.GET)
    public Set<Object> zRangeByScore(@PathVariable(value = "key") String key, @RequestParam("min") Long min, @RequestParam(value = "max") Long max);



    // 对hash结构的某一个field进行incr操作
    @PostMapping("/hincr")
    public Long hincr(@RequestParam(value = "key")String key,@RequestParam(value = "field")String field,
                      @RequestParam(value = "delta")Long delta);


}
